home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / GNUUCP_2 / SOURCE / SYSDEP.ST < prev    next >
Text File  |  1989-07-31  |  4KB  |  218 lines

  1. /*
  2.  * @(#)sysdep.st 1.3 87/09/23    Copyright 1987 Free Software Foundation, Inc.
  3.  *
  4.  * Copying and use of this program are controlled by the terms of the
  5.  * GNU Emacs General Public License.
  6.  */
  7.  
  8. #ifndef lint
  9. char sysdep_version[] = "@(#)sysdep.st gnuucp Version hoptoad-1.3";
  10. #endif
  11.  
  12. #include "includes.h"
  13. #include "uucp.h"
  14. #include "sysdep.h"
  15.  
  16. #define AUX        1    /* rs232 port */
  17. #define CON        2    /* console */
  18. #define CTRL(X)    (X & 037)
  19.  
  20. /* Our variables */
  21. jmp_buf alarming;            /* For read timeouts */
  22. void sigint();                /* Forward declaration */
  23.  
  24.  
  25. /*
  26.  * Open the serial line for an incoming call.
  27.  * Argument of NULL or empty string means stdin.
  28.  */
  29. int
  30. openline(ttynam, baud)
  31.     char    *ttynam;
  32.     int    baud;
  33. {
  34.     /* FIXME, honor specified baudrate */
  35.     /* set 1200 baud, no flow ctrl. */
  36.     Rsconf(7, 0, -1, -1, -1, -1);
  37.     /* FIXME, these numbers (at least the 7!) should be replaced
  38.      * with symbolic constants, preferably from a system header
  39.      * file */
  40.  
  41.     /* setup user abort */
  42.     if (setjmp(abortenv))
  43.         exit(0);
  44. }
  45.  
  46. /*
  47.  * Basement level I/O routines
  48.  *
  49.  * xwrite() writes a character string to the serial port
  50.  * xgetc() returns a character from the serial port, or an EOF for timeout.
  51.  * sigint() restores the state of the serial port on exit.
  52.  */
  53.  
  54. void
  55. sigint()
  56. {
  57.     /* Restore terminal settings on dialout line */
  58.  
  59.     /* No need to do anything here? */
  60.     exit(0);
  61. }
  62.  
  63.  
  64. /*
  65.  * xwrite(dummy, buf, n) - write "n" bytes from buffer "buf" to rs232 port.
  66.  */
  67. xwrite(dummy, buf, n)
  68.     int dummy, n;
  69.     char *buf;
  70. {
  71.     register char *c = buf;
  72.  
  73.     while (n) {
  74.         /* wait for rs232 to be ready */
  75.         while (Bcostat(AUX) == 0)
  76.             ;
  77.  
  78.         /* write next character in buffer */
  79.         Bconout(AUX, c++);
  80.         n--;
  81.     }
  82. }
  83.  
  84. /*
  85.  * Serial port reading routines
  86.  */
  87.  
  88. /*
  89.  * Atari ST routines for reading the comm port.
  90.  *
  91.  * The following routines come by way of J. R. Bammi
  92.  */
  93.  
  94. long prtime = 0L;            /* present time            */
  95. long alrmtime = 0L;            /* alarm time            */
  96. long *hz200 = (long *)0x0004ba;        /* address of system 200 hz clk    */
  97. jmp_buf abortenv;            /* used to catch user aborts    */
  98.  
  99. /*
  100.  * read200hz() - read the system 200 hz clock.
  101.  */
  102. void read200hz()
  103. {
  104.     prtime = *hz200;
  105. }
  106.  
  107. /*
  108.  * alarm(n) - set the alarm time to n seconds.
  109.  */
  110. void alarm(n)
  111.     unsigned int n;
  112. {
  113.     /* if n != 0, then set the alarm time */
  114.     if (n) {
  115.         Supexec(read200hz);
  116.         alrmtime = prtime + (long)(200 * n);
  117.  
  118.     /* n == 0, reset alarm time */
  119.     } else
  120.         alrmtime = 0L;
  121. }
  122.  
  123. /*
  124.  * xgetc() - get a character from the rs232 port, catch timeouts & aborts.
  125.  */
  126. xgetc()
  127. {
  128.     if (setjmp(alarming))
  129.         return(EOF);
  130.     alarm(BYTE_TIMEOUT);
  131.     while (1) {
  132.         /* catch ^C (user abort) */
  133.         if (Bconstat(CON))
  134.             if ((int)Bconin(CON) == CTRL('C'))
  135.                 longjmp(abortenv, 1);
  136.  
  137.         /* check for a char at rs232 port */
  138.         if (Bconstat(AUX)) {
  139.             alarm(0);
  140.             return((int)Bconin(AUX));
  141.  
  142.         /* no char, check for timeout */
  143.         } else if (alrmtime) {
  144.             Supexec(read200hz);
  145.             if (prtime >= alrmtime)
  146.                 longjmp(alarming, 1);
  147.         }
  148.     }
  149. }
  150.  
  151. /* CP/M and MSDOS and ST need these routines.  Probably should use
  152.  * the new names, but for now...
  153.  */
  154. bzero(s, cnt)
  155. register char    *s;
  156. register int    cnt;
  157. {
  158.     register int    i;
  159.     for (i = 0; i < cnt; i++) {
  160.         *s++ = '\0';
  161.     }
  162. }
  163.  
  164. bcopy(from, to, cnt)
  165. register char    *from;
  166. register char    *to;
  167. register int    cnt;
  168. {
  169.     register int    i;
  170.     for (i = 0; i < cnt; i++) {
  171.         *to++ = *from++;
  172.     }
  173. }
  174.  
  175. /*
  176.  * Create a temporary file name for receiving a file into.
  177.  * "name" is the name we will actually eventually want to use for the file.
  178.  * We currently ignore it, but some OS's that can't move files around
  179.  * easily might want to e.g. put the temp file into the same directory
  180.  * that this file is going into.
  181.  *
  182.  * FIXME:
  183.  * This interface should be able to return a "possible" filename, and
  184.  * be re-called if the name is already in use, to get another.
  185.  * This avoids checking here whether the name is good -- saving system calls.
  186.  */
  187. char *
  188. temp_filename(name)
  189.     register char *name;
  190. {
  191.     static char tname[NAMESIZE];
  192.  
  193.     FIXME;
  194.     DEBUG(6,"Using temp file %s\n", tname);
  195.     return tname;
  196. }
  197.  
  198.  
  199. /*
  200.  * Transform a filename from a uucp packet (in Unix format) into a local
  201.  * filename that will work in the local file system.
  202.  */
  203. char *
  204. munge_filename(name)
  205.     register char *name;
  206. {
  207.     register char *p;
  208.  
  209. #ifdef DEBUG
  210.     printf("Munge_filename  input: %s\n", name);
  211. #endif
  212.     FIXME;
  213. #ifdef DEBUG
  214.     printf("Munge_filename output: %s\n", p);
  215. #endif
  216.     return p;
  217. }
  218.